#ifndef _xmlbuilder_h_
#define _xmlbuilder_h_

#include <string>
#include <vector>
#include "base/scoped_ptr.h"
#include "xmllite/xmlparser.h"

#ifdef EXPAT_RELATIVE_PATH
#include "expat.h"
#else
#include "third_party/expat/v2_0_1/Source/lib/expat.h"
#endif  // EXPAT_RELATIVE_PATH

namespace buzz {

	class XmlElement;
	class XmlParseContext;


	class XmlBuilder : public XmlParseHandler {
	public:
		XmlBuilder();

		static XmlElement * BuildElement(XmlParseContext * pctx,
			const char * name, const char ** atts);
		virtual void StartElement(XmlParseContext * pctx,
			const char * name, const char ** atts);
		virtual void EndElement(XmlParseContext * pctx, const char * name);
		virtual void CharacterData(XmlParseContext * pctx,
			const char * text, int len);
		virtual void Error(XmlParseContext * pctx, XML_Error);
		virtual ~XmlBuilder();

		void Reset();

		// Take ownership of the built element; second call returns NULL
		XmlElement * CreateElement();

		// Peek at the built element without taking ownership
		XmlElement * BuiltElement();

	private:
		XmlElement * pelCurrent_;
		base::scoped_ptr<XmlElement> pelRoot_;
		base::scoped_ptr<std::vector<XmlElement*> > pvParents_;
	};

}

#endif
